package csel.controller.factories;

import csel.controller.commands.ChangeToGameViewCommand;
import csel.controller.commands.UpdateViewCommand;
import csel.model.GameCommand;
import csel.model.Model;
import csel.view.AreaViewport;
import csel.view.Splasher;
import csel.view.StatusViewport;

/**
 * Reasons for Existence: implements a factory method which returns an object 
 * of type GameCommand which can be used by the view</br>
 * Team Members Responsible</br>
 * Implementation: Nik, Tait</br>
 * Testing: Nik, Tait</br> 
 * 
 * @author Nikolas Wolfe
 */
public class ViewCommandFactory implements CommandFactory
{
	// Instance variables
	private Model model;
	private StatusViewport statusViewport;
	private AreaViewport areaViewport;
	private Splasher splashViewport;
	private CommandFactory currFactory;

	// constuctor
	public ViewCommandFactory(
			Model model,
			Splasher splashViewport,
			AreaViewport areaViewport,
			StatusViewport statusViewport)
	{
		this.model = model;
		this.areaViewport = areaViewport;
		this.statusViewport = statusViewport;
		this.splashViewport = splashViewport;
	}

	// public interface 
	public GameCommand createGameCommand()
	{
		return currFactory.createGameCommand();
	}

	// This is a change view command for the view
	public void newChangeToGameViewCommandFactory()
	{
		currFactory = new ChangeToGameViewCommandFactory();
	}

	// This is a update view command for the view 
	public void newUpdateViewCommandFactory()
	{
		currFactory = new UpdateViewCommandFactory();
	}
	
	// New Game Command Factory
	private class ChangeToGameViewCommandFactory implements CommandFactory
	{
		private final GameCommand gameCommand;

		public ChangeToGameViewCommandFactory()
		{
			this.gameCommand = new ChangeToGameViewCommand( splashViewport, statusViewport, areaViewport );
		}

		public GameCommand createGameCommand()
		{
			return this.gameCommand;
		}
	}
	
	// update the view Factory
	private class UpdateViewCommandFactory implements CommandFactory
	{
		private final GameCommand gameCommand;

		public UpdateViewCommandFactory()
		{
			this.gameCommand = new UpdateViewCommand( statusViewport );
		}

		public GameCommand createGameCommand()
		{
			return this.gameCommand;
		}
	}
}
